// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the BigLake API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_biglake_v1::client::IcebergCatalogService;
/// let client = IcebergCatalogService::builder().build().await?;
/// // use `client` to make requests to the BigLake API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Iceberg Catalog Service API: this implements the open-source Iceberg REST
/// Catalog API.
/// See the API definition here:
/// <https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml>
///
/// The API is defined as OpenAPI 3.1.1 spec.
///
/// Currently we only support the following methods:
///
/// - GetConfig/GetIcebergCatalogConfig
/// - ListIcebergNamespaces
/// - CheckIcebergNamespaceExists
/// - GetIcebergNamespace
/// - CreateIcebergNamespace (only supports single level)
/// - DeleteIcebergNamespace
/// - UpdateIcebergNamespace properties
/// - ListTableIdentifiers
/// - CreateIcebergTable
/// - DeleteIcebergTable
/// - GetIcebergTable
/// - UpdateIcebergTable (CommitTable)
/// - LoadIcebergTableCredentials
/// - RegisterTable
///
/// Users are required to provided the `X-Goog-User-Project` header with the
/// project id or number which can be different from the bucket project id.
/// That project will be charged for the API calls and the calling user must have
/// access to that project. The caller must have `serviceusage.services.use`
/// permission on the project.
///
/// # Configuration
///
/// To configure `IcebergCatalogService` use the `with_*` methods in the type returned
/// by [builder()][IcebergCatalogService::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://biglake.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::iceberg_catalog_service::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::iceberg_catalog_service::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `IcebergCatalogService` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `IcebergCatalogService` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct IcebergCatalogService {
    inner: std::sync::Arc<dyn super::stub::dynamic::IcebergCatalogService>,
}

impl IcebergCatalogService {
    /// Returns a builder for [IcebergCatalogService].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_biglake_v1::client::IcebergCatalogService;
    /// let client = IcebergCatalogService::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::iceberg_catalog_service::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::iceberg_catalog_service::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::IcebergCatalogService + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::IcebergCatalogService>>
    {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::IcebergCatalogService> {
        super::transport::IcebergCatalogService::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::IcebergCatalogService> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::IcebergCatalogService::new)
    }

    /// GetIcebergCatalogConfig lists all catalog configuration settings. Most
    /// importantly it contains the optional `endpoints` field which lists what
    /// methods this catalog supports, since we are not supporting all the methods
    /// right now.
    /// It returns all the methods defined in this service (subject to project
    /// config allowlisting).
    ///
    /// This is not a GCP resource.
    pub fn get_iceberg_catalog_config(
        &self,
    ) -> super::builder::iceberg_catalog_service::GetIcebergCatalogConfig {
        super::builder::iceberg_catalog_service::GetIcebergCatalogConfig::new(self.inner.clone())
    }

    /// Lists Iceberg namespaces in the catalog. We only support one level of
    /// nesting for namespaces.
    pub fn list_iceberg_namespaces(
        &self,
    ) -> super::builder::iceberg_catalog_service::ListIcebergNamespaces {
        super::builder::iceberg_catalog_service::ListIcebergNamespaces::new(self.inner.clone())
    }

    /// Gets an Iceberg namespace in the catalog (or checks if it exists, if the
    /// method is HEAD).
    pub fn get_iceberg_namespace(
        &self,
    ) -> super::builder::iceberg_catalog_service::GetIcebergNamespace {
        super::builder::iceberg_catalog_service::GetIcebergNamespace::new(self.inner.clone())
    }

    /// Creates a namespace in the catalog.
    pub fn create_iceberg_namespace(
        &self,
    ) -> super::builder::iceberg_catalog_service::CreateIcebergNamespace {
        super::builder::iceberg_catalog_service::CreateIcebergNamespace::new(self.inner.clone())
    }

    /// Returns 204, not 200 on success.
    pub fn delete_iceberg_namespace(
        &self,
    ) -> super::builder::iceberg_catalog_service::DeleteIcebergNamespace {
        super::builder::iceberg_catalog_service::DeleteIcebergNamespace::new(self.inner.clone())
    }

    /// Updates namespace properties.
    pub fn update_iceberg_namespace(
        &self,
    ) -> super::builder::iceberg_catalog_service::UpdateIcebergNamespace {
        super::builder::iceberg_catalog_service::UpdateIcebergNamespace::new(self.inner.clone())
    }

    /// Lists table identifiers (not *tables*) in the namespace.
    pub fn list_iceberg_table_identifiers(
        &self,
    ) -> super::builder::iceberg_catalog_service::ListIcebergTableIdentifiers {
        super::builder::iceberg_catalog_service::ListIcebergTableIdentifiers::new(
            self.inner.clone(),
        )
    }

    /// Creates a table in the namespace.
    pub fn create_iceberg_table(
        &self,
    ) -> super::builder::iceberg_catalog_service::CreateIcebergTable {
        super::builder::iceberg_catalog_service::CreateIcebergTable::new(self.inner.clone())
    }

    /// Deletes a table in the namespace.
    pub fn delete_iceberg_table(
        &self,
    ) -> super::builder::iceberg_catalog_service::DeleteIcebergTable {
        super::builder::iceberg_catalog_service::DeleteIcebergTable::new(self.inner.clone())
    }

    /// Gets a table in the namespace.
    pub fn get_iceberg_table(&self) -> super::builder::iceberg_catalog_service::GetIcebergTable {
        super::builder::iceberg_catalog_service::GetIcebergTable::new(self.inner.clone())
    }

    /// Loads credentials for a table in the namespace.
    pub fn load_iceberg_table_credentials(
        &self,
    ) -> super::builder::iceberg_catalog_service::LoadIcebergTableCredentials {
        super::builder::iceberg_catalog_service::LoadIcebergTableCredentials::new(
            self.inner.clone(),
        )
    }

    /// This is CommitTable Iceberg API, which maps to `UpdateIcebergTable` in the
    /// Google API nomenclature.
    pub fn update_iceberg_table(
        &self,
    ) -> super::builder::iceberg_catalog_service::UpdateIcebergTable {
        super::builder::iceberg_catalog_service::UpdateIcebergTable::new(self.inner.clone())
    }

    /// Register a table using given metadata file location.
    pub fn register_iceberg_table(
        &self,
    ) -> super::builder::iceberg_catalog_service::RegisterIcebergTable {
        super::builder::iceberg_catalog_service::RegisterIcebergTable::new(self.inner.clone())
    }

    /// Returns the Iceberg REST Catalog configuration options.
    pub fn get_iceberg_catalog(
        &self,
    ) -> super::builder::iceberg_catalog_service::GetIcebergCatalog {
        super::builder::iceberg_catalog_service::GetIcebergCatalog::new(self.inner.clone())
    }

    /// Lists the Iceberg REST Catalogs.
    pub fn list_iceberg_catalogs(
        &self,
    ) -> super::builder::iceberg_catalog_service::ListIcebergCatalogs {
        super::builder::iceberg_catalog_service::ListIcebergCatalogs::new(self.inner.clone())
    }

    /// Deletes the Iceberg REST Catalog.
    /// Delete does not delete a catalog that has contents -- at least one
    /// namespace.
    ///
    /// Delete is not supported for all catalog types.
    pub fn delete_iceberg_catalog(
        &self,
    ) -> super::builder::iceberg_catalog_service::DeleteIcebergCatalog {
        super::builder::iceberg_catalog_service::DeleteIcebergCatalog::new(self.inner.clone())
    }

    /// Update the Iceberg REST Catalog configuration options.
    pub fn update_iceberg_catalog(
        &self,
    ) -> super::builder::iceberg_catalog_service::UpdateIcebergCatalog {
        super::builder::iceberg_catalog_service::UpdateIcebergCatalog::new(self.inner.clone())
    }

    /// Creates the Iceberg REST Catalog.
    /// Currently only supports Google Cloud Storage Bucket catalogs.
    /// Google Cloud Storage Bucket catalog id is the bucket for which the
    /// catalog is created (e.g. `my-catalog` for `gs://my-catalog`).
    ///
    /// If the bucket does not exist, of the caller does not have bucket metadata
    /// permissions, the catalog will not be created.
    pub fn create_iceberg_catalog(
        &self,
    ) -> super::builder::iceberg_catalog_service::CreateIcebergCatalog {
        super::builder::iceberg_catalog_service::CreateIcebergCatalog::new(self.inner.clone())
    }

    /// Failover the catalog to a new primary replica region.
    pub fn failover_iceberg_catalog(
        &self,
    ) -> super::builder::iceberg_catalog_service::FailoverIcebergCatalog {
        super::builder::iceberg_catalog_service::FailoverIcebergCatalog::new(self.inner.clone())
    }
}
